package org.demo.five;
/**
 * 
 * @author  
 * @date    2010-10-24
 * @file    org.demo.five.PersonProxy.java
 */
public class PersonProxy implements java.io.Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public String data;
	public PersonProxy(Person orig){
		data = orig.getFirstName() + "," 
		     + orig.getlastName() + ","
		     + orig.getAge();
		if (orig.getSpouse() != null){
			Person spouse = orig.getSpouse();
			data += "," + spouse.getFirstName() + ","
			      + spouse.getlastName() + ","
			      + spouse.getAge();
		}
	}
	private Object readResolve(){
		System.out.println("-- proxy readResolve --");
		String[] pieces = data.split(",");
		Person result = new Person(pieces[0],pieces[1],Integer.parseInt(pieces[2]));
		if (pieces.length > 3){
			Person spouse = new Person(pieces[3],pieces[4],Integer.parseInt(pieces[5]));
			spouse.setSpouse(result);
			result.setSpouse(spouse);
		}
		return result;
	}
}